<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>后台管理模板</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="../../css/global.css" media="all">
	<link rel="stylesheet" type="text/css" href="http://www.jq22.com/jquery/font-awesome.4.6.0.css">
	<link rel="stylesheet" href="../../datatables/media/css/jquery.dataTables.css">
	<link rel="stylesheet" href="../../datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.css">
	<link rel="stylesheet" type="text/css" href="../../css/dateRange.css">
	<style type="text/css">
		.voucher-content {
			margin-top: 65px;
			margin-left: 40px;
			font-size: 14px
		}
		table.dateRangeDateTable th:first-child, table.dateRangeDateTable td:first-child {
			width: inherit;
		}
	</style>
</head>
<body>
	<div class="layui-layout layui-layout-admin" style="border-bottom: solid 5px #1aa094;">
		<!--头部导航-->
		<div class="layui-header header header-demo" ></div>
		<!--左侧导航-->
		<div class="layui-side layui-bg-black" id="admin-side">
		</div>
		<!--右侧具体内容-->
		<div class="layui-body" style="bottom: 0;border-left: solid 2px #1AA094;padding:20px" id="admin-body">
			<div>
				<div class="title">添加代金券</div>
			</div>
			<hr/>
			<div class="voucher-content">
				<form class="layui-form" action="">
					<div class="layui-form-item" style="margin-right: 800px">
						<label class="layui-form-label">代金券名称</label>
						<div class="layui-input-block">
							<input type="text" name="voucherName" required  lay-verify="required" placeholder="请输入代金券名称" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item" style="margin-right: 800px">
						<label class="layui-form-label">代金券金额</label>
						<div class="layui-input-block">
							<input type="text" name="voucherPrice" required  lay-verify="required" placeholder="请输入代金券金额" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item" style="margin-right: 800px">
						<label class="layui-form-label">所需积分</label>
						<div class="layui-input-block">
							<input type="text" name="voucherScore" required  lay-verify="required" placeholder="请输入所需积分" autocomplete="off" class="layui-input">
						</div>
					</div>

					<div class="layui-form-item" style="margin-right: 800px">
						<label class="layui-form-label">有效天数</label>
						<div class="layui-input-block">
							<input type="text" name="voucherDate" required  lay-verify="required" placeholder="请输入有效期" autocomplete="off" class="layui-input">
						</div>
					</div>

					<div class="layui-form-item" >
						<label class="layui-form-label" >日期区间</label>


						<div class="layui-input-block">
							<div class="ta_date" id="div_date_demo3">
								<span class="date_title" id="date_demo3">2017-07-13 至 2017-07-19</span>
								<a class="opt_sel" id="input_trigger_demo3" href="#">
									<i class="i_orderd"></i>
								</a>
							</div>
						</div>
						<label>(在代金券商城显示的时间)</label>


					</div>


				</form>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn" lay-submit lay-filter="formDemo" id="confirmadd">确认添加</button>
					</div>
				</div>
			</div>
			<!--底部导航-->
			<div class="layui-footer footer footer-demo" id="admin-footer"></div>
			<!--JS模块-->
			<script type="text/javascript" src="../../layui/layui.js"></script>
			<script src="../../js/jquery-1.12.3.min.js"></script>
			<script src="../../js/index.js"></script>
			<script type="text/javascript" src="../../js/jquery.cookie.js"></script>
			<script type="text/javascript" src="../../js/dateRange.js"></script>
			<script>
				var data = {
					"code": 200
				}
				//var vouchersDate
				var startDate
				var endDate
				layui.use('form', function() {
					var form = layui.form();
					var dateRange = new pickerDateRange('date_demo3', {
						isTodayValid: true,
						startDate: '请选择时间',
						// endDate: '2017-07-21',
						// defaultText: ' 至 ',
						inputTrigger: 'input_trigger_demo3',
						theme: 'ta',
						stopToday: false, //天数：每天都能选
						success: function(obj) {
							// alert($("#this.startCompareDateId").text)
							// alert($('#' + this.startDateId).val())
							// alert($('#' + this.endDateId).val())
							startTime = new Date($('#' + this.startDateId).val().replace(/-/g, "/"));
							endTime = new Date($('#' + this.endDateId).val().replace(/-/g, "/"));
							//vouchersDate = (endTime - startTime) / (1000 * 60 * 60 * 24)
						}
					});

				});
					$(document).on("click","#confirmadd",function() {
					// $("#confirmadd").on("click", function() {
						/*alert($("input[name='voucherName']").val())
						alert($("input[name='voucherPrice']").val())
						alert($("input[name='voucherScore']").val())
						alert(startTime)
						alert(endTime)*/
						$.ajax(
						{
							type: "POST",
							url: "/randomdelivery/VoucherController/voucher",
							data: JSON.stringify(
							{
								"vouchersName": $("input[name='voucherName']").val(),
								"vouchersPrice": $("input[name='voucherPrice']").val(),
								"vouchersScore": $("input[name='voucherScore']").val(),
								"vouchersDate": $("input[name='voucherDate']").val(),
								"vouchersCreatetime":startTime,
								"vouchersFailuretime": endTime,
								"vouchersState": 1,
								"vouchersType": 1
							}),
							async: true,
							dataType: "json",
							contentType: "application/json",
							success: function(data) 
							{
									//alert(456)
								if (data.code == 200) 
								{
									alert("添加代金券成功")
							window.location.href = "voucher.html"
						};
					},
					Error: function() 
					{
						alert("服务器出错");
					}
					});
					})

			</script>
		</div>
	</div>
</body>
</html>